import time
from multiprocessing import Pool, current_process


def method1(param):
    time.sleep(1)
    print("参数为 %s ,当前进程为 %s" % (param, current_process().name))


if __name__ == '__main__':
    pool = Pool(processes=4)
    print("主进程为 %s" % current_process().name)
    start_time = time.time()
    for i in range(10):
        # 异步执行较快
        pool.apply_async(method1, args=(i,))
        # 同步执行较慢
        # pool.apply(method1, args=(i,))
    pool.close()
    # 等待所有进程执行完毕 ,堵塞主进程
    pool.join()
    print("总耗时 %s 妙" % (time.time() - start_time))
    print("主进程结束")
